/*     */ package com.qmsk.business.order.order.controller;
/*     */ 
/*     */ import com.qmsk.business.bussBill.bussBill.dao.BussBillDao;
/*     */ import com.qmsk.business.member.memberIntegralConsumeRecord.dao.MemberIntegralConsumeRecordDAO;
/*     */ import com.qmsk.business.member.memberdepositbill.dao.MemberDepositBillDAO;
/*     */ import com.qmsk.business.member.shopMember.dao.ShopMemberDAO;
/*     */ import com.qmsk.business.order.cart.dao.CartDAO;
/*     */ import com.qmsk.business.order.order.dao.OrderDAO;
/*     */ import com.utils.gson.in.GsonHeadOneRow;
/*     */ import com.utils.gson.out.GsonEbRst;
/*     */ import com.utils.jdbc.connection.DbConnection;
/*     */ import com.utils.web.RequestUtils;
/*     */ import com.utils.web.ResponseUtils;
/*     */ import java.util.Date;
/*     */ import javax.servlet.http.HttpServletRequest;
/*     */ import javax.servlet.http.HttpServletResponse;
/*     */ import org.apache.log4j.Logger;
/*     */ import org.springframework.beans.factory.annotation.Autowired;
/*     */ import org.springframework.stereotype.Controller;
/*     */ import org.springframework.web.bind.annotation.PathVariable;
/*     */ import org.springframework.web.bind.annotation.RequestMapping;
/*     */ 
/*     */ @Controller
/*     */ @RequestMapping({"order"})
/*     */ public class OrderController
/*     */ {
/*  32 */   private Logger logger = Logger.getLogger(OrderController.class);
/*     */ 
/*     */   @Autowired
/*     */   private OrderDAO dao;
/*     */ 
/*     */   @Autowired
/*     */   private CartDAO cartDAO;
/*     */ 
/*     */   @Autowired
/*     */   private ShopMemberDAO shopMemberDAO;
/*     */ 
/*     */   @Autowired
/*     */   private MemberDepositBillDAO memberDepositBillDAO;
/*     */ 
/*     */   @Autowired
/*     */   private MemberIntegralConsumeRecordDAO memberIntegralConsumeRecordDAO;
/*     */ 
/*     */   @Autowired
/*     */   private BussBillDao bussBillDao;
/*     */ 
/*     */   @RequestMapping(value={"pay/{orderId}/{openId}/{shopId}"}, method={org.springframework.web.bind.annotation.RequestMethod.POST})
/*     */   public void pay(HttpServletRequest request, HttpServletResponse response, @PathVariable("orderId") Long orderId, @PathVariable("shopId") Long shopId, @PathVariable("openId") String openId)
/*     */   {
/*     */     try
/*     */     {
/*  62 */       Long memberId = this.dao.getMemberIdByOpenId(openId);
/*  63 */       if (memberId == null) {
/*  64 */         ResponseUtils.setErrorMsgResponse("您还不是会员，不能支付！", response);
/*  65 */         DbConnection.rollback();
/*  66 */         return;
/*     */       }
/*     */ 
/*  72 */       GsonHeadOneRow payInfo = this.dao.getOrderPayInfo(openId, orderId);
/*  73 */       if ((payInfo == null) || (payInfo.getDataLength() == 0)) {
/*  74 */         ResponseUtils.setErrorMsgResponse("订单不存在，支付失败！", response);
/*  75 */         DbConnection.rollback();
/*  76 */         return;
/*     */       }
/*  78 */       Integer payIntegral = (Integer)payInfo.getValueOfName("integral");
/*  79 */       if ((payIntegral == null) || (payIntegral.intValue() < 0)) {
/*  80 */         ResponseUtils.setErrorMsgResponse("订单不存在，支付失败！", response);
/*  81 */         DbConnection.rollback();
/*  82 */         return;
/*     */       }
/*     */ 
/*  89 */       Integer memberIntegral = this.dao.getMemberIntegral(memberId, shopId);
/*     */ 
/*  91 */       if (payIntegral.intValue() > memberIntegral.intValue())
/*     */       {
/*  95 */         ResponseUtils.setErrorMsgResponse("积分不足，支付失败！", response);
/*  96 */         DbConnection.rollback();
/*  97 */         return;
/*     */       }
/*     */ 
/* 105 */       String billNO = this.bussBillDao.getMaxBillNo(shopId);
/* 106 */       String[] head = { "ShopID", "BillNo", "MemberID", 
/* 107 */         "PayIntAmtMny", "stID" };
/* 108 */       Object[] list = { shopId, billNO, memberId, 
/* 109 */         payIntegral, Integer.valueOf(200) };
/* 110 */       GsonHeadOneRow row = new GsonHeadOneRow(head, list);
/* 111 */       int n = this.bussBillDao.insertGsonHeadOneRow(row);
/* 112 */       if (n <= 0) {
/* 113 */         ResponseUtils.setErrorMsgResponse("支付失败，错误码：OP01", response);
/* 114 */         DbConnection.rollback();
/* 115 */         return;
/*     */       }
/*     */ 
/* 118 */       Long bussId = this.bussBillDao.getLastId();
/* 119 */       if (bussId == null) {
/* 120 */         ResponseUtils.setErrorMsgResponse("支付失败，错误码：OP02", response);
/* 121 */         DbConnection.rollback();
/* 122 */         return;
/*     */       }
/*     */ 
/* 125 */       head = new String[] { "IntegralAmount", "MemberID", "shopId" };
/* 126 */       list = new Object[] { Integer.valueOf(memberIntegral.intValue() - payIntegral.intValue()), memberId, 
/* 127 */         shopId };
/* 128 */       row = new GsonHeadOneRow(head, list);
/* 129 */       n = this.shopMemberDAO.updateJsonHeadOneRow(row, "crm_shop_member");
/* 130 */       if (n <= 0) {
/* 131 */         ResponseUtils.setErrorMsgResponse("支付失败，错误码：OP03", response);
/* 132 */         DbConnection.rollback();
/* 133 */         return;
/*     */       }
/*     */ 
/* 136 */       head = new String[] { "WorkNo", "Date", "ConsumeIntegral", 
/* 137 */         "BussID", "Memo", "memberId" };
/* 138 */       list = new Object[] { billNO, new Date(), payIntegral, bussId, 
/* 139 */         "微信商城支付，订单号：" + orderId, memberId };
/* 140 */       row = new GsonHeadOneRow(head, list);
/* 141 */       n = this.memberIntegralConsumeRecordDAO.insertGsonHeadOneRow(row);
/* 142 */       if (n <= 0) {
/* 143 */         ResponseUtils.setErrorMsgResponse("支付失败，错误码：OP04", response);
/* 144 */         DbConnection.rollback();
/* 145 */         return;
/*     */       }
/*     */ 
/* 148 */       head = new String[] { "status", "payTime", "payMemo", "payType", 
/* 149 */         "orderId" };
/* 150 */       list = new Object[] { Integer.valueOf(1), new Date(), "会员积分支付", Integer.valueOf(0), orderId };
/* 151 */       row = new GsonHeadOneRow(head, list);
/* 152 */       n = this.dao.updateJsonHeadOneRow(row, "crm_order");
/* 153 */       if (n <= 0) {
/* 154 */         ResponseUtils.setErrorMsgResponse("支付失败，错误码：OP05", response);
/* 155 */         DbConnection.rollback();
/* 156 */         return;
/*     */       }
/*     */ 
/* 159 */       ResponseUtils.setSuccessResponse(response);
/* 160 */       DbConnection.commit();
/*     */     } catch (Exception e) {
/* 162 */       DbConnection.rollback();
/* 163 */       this.logger.error(e);
/* 164 */       ResponseUtils.setErrorMsgResponse(
/* 165 */         RequestUtils.getFindDataErrorMessage(request), response);
/*     */     }
/*     */   }
/*     */ 
/*     */   @RequestMapping(value={"del/{orderId}"}, method={org.springframework.web.bind.annotation.RequestMethod.POST})
/*     */   public void deleteOrder(HttpServletRequest request, HttpServletResponse response, @PathVariable("orderId") Long orderId)
/*     */   {
/*     */     try
/*     */     {
/* 174 */       Integer status = this.dao.getOrderStatus(orderId);
/* 175 */       if (status.intValue() != 0) {
/* 176 */         ResponseUtils.setErrorMsgResponse("订单不可编辑！", response);
/* 177 */         return;
/*     */       }
/*     */ 
/* 183 */       int n = this.dao.deleteParams(new Object[] { orderId });
/* 184 */       if (n <= 0) {
/* 185 */         ResponseUtils.setErrorMsgResponse("操作失败！", response);
/* 186 */         DbConnection.rollback();
/* 187 */         return;
/*     */       }
/*     */ 
/* 190 */       n = this.cartDAO.delteOrder(orderId);
/* 191 */       if (n <= 0) {
/* 192 */         ResponseUtils.setErrorMsgResponse("操作失败！", response);
/* 193 */         DbConnection.rollback();
/* 194 */         return;
/*     */       }
/*     */ 
/* 197 */       DbConnection.commit();
/* 198 */       ResponseUtils.setSuccessResponse(response);
/*     */     } catch (Exception e) {
/* 200 */       DbConnection.rollback();
/* 201 */       this.logger.error(e);
/* 202 */       ResponseUtils.setErrorMsgResponse(
/* 203 */         RequestUtils.getFindDataErrorMessage(request), response);
/*     */     }
/*     */   }
/*     */ 
/*     */   @RequestMapping(value={"detail/list/{openId}"}, method={org.springframework.web.bind.annotation.RequestMethod.GET})
/*     */   public void orderDetailList(HttpServletRequest request, HttpServletResponse response, @PathVariable("openId") String openId)
/*     */   {
/*     */     try {
/* 211 */       GsonEbRst rst = this.dao.getOrderDetailList(openId);
/* 212 */       ResponseUtils.setResponseResult(rst, response);
/*     */     } catch (Exception e) {
/* 214 */       this.logger.error(e);
/* 215 */       ResponseUtils.setErrorMsgResponse(
/* 216 */         RequestUtils.getFindDataErrorMessage(request), response);
/*     */     }
/*     */   }
/*     */ 
/*     */   @RequestMapping(value={"submit/{shopId}/{openId}"}, method={org.springframework.web.bind.annotation.RequestMethod.POST})
/*     */   public void submit(HttpServletRequest request, HttpServletResponse response, @PathVariable("shopId") Long shopId, @PathVariable("openId") String openId)
/*     */   {
/*     */     try
/*     */     {
/* 225 */       Integer countries = RequestUtils.getInt(request, "countries");
/* 226 */       String detailAddress = RequestUtils.getString(request, 
/* 227 */         "detailAddress");
/* 228 */       String receiveName = RequestUtils.getString(request, "receiveName");
/* 229 */       String mp = RequestUtils.getString(request, "mp");
/*     */ 
/* 231 */       String orderNo = this.memberDepositBillDAO.getMaxBillNo(shopId);
/* 232 */       Float money = this.cartDAO.getTotalMoney(openId);
/* 233 */       Integer integral = this.cartDAO.getTotalIntegral(openId);
/* 234 */       String[] head = { "orderNo", "shopId", "openId", 
/* 235 */         "orderFrom", "money", "integral", "receiver", "mp", 
/* 236 */         "address", "detailAddress", "status", "createFileTime" };
/*     */ 
/* 238 */       Object[] list = { orderNo, shopId, openId, "WX", 
/* 239 */         money, integral, receiveName, mp, countries, detailAddress, 
/* 240 */         Integer.valueOf(0), new Date() };
/*     */ 
/* 242 */       GsonHeadOneRow row = new GsonHeadOneRow(head, list);
/* 243 */       int n = this.dao.insertGsonHeadOneRow(row);
/* 244 */       if (n <= 0) {
/* 245 */         ResponseUtils.setErrorMsgResponse("提交失败！", response);
/* 246 */         DbConnection.rollback();
/* 247 */         return;
/*     */       }
/*     */ 
/* 250 */       Long orderId = this.dao.getLastId();
/* 251 */       if (orderId == null) {
/* 252 */         ResponseUtils.setErrorMsgResponse("提交失败！", response);
/* 253 */         DbConnection.rollback();
/* 254 */         return;
/*     */       }
/*     */ 
/* 257 */       n = this.cartDAO.updateSubmitOrder(orderId, openId);
/* 258 */       if (n <= 0) {
/* 259 */         ResponseUtils.setErrorMsgResponse("提交失败！", response);
/* 260 */         DbConnection.rollback();
/* 261 */         return;
/*     */       }
/* 263 */       ResponseUtils.setSuccessResponse(response);
/* 264 */       DbConnection.commit();
/*     */     } catch (Exception e) {
/* 266 */       DbConnection.rollback();
/* 267 */       this.logger.error(e);
/* 268 */       ResponseUtils.setErrorMsgResponse(
/* 269 */         RequestUtils.getFindDataErrorMessage(request), response);
/*     */     }
/*     */   }
/*     */ }

/* Location:           C:\Users\Administrator\Desktop\新建文件夹\WEB-INF\classes\
 * Qualified Name:     com.qmsk.business.order.order.controller.OrderController
 * JD-Core Version:    0.5.3
 */